package com.xiaomage.view.draw4

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.view.View





/**
 * Created by Administrator on 2018/1/2.
 */
class CanvasView(context: Context):View(context) {
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        //定义画笔
        val paint= Paint()
        paint.isAntiAlias=true
        paint.style=Paint.Style.STROKE
        paint.strokeWidth=5f
        paint.color= Color.parseColor("#448ced")

        //val rect=Rect(0,0,200,200)
        //canvas.drawRect(rect,paint)

        //canvas.translate(100f,100f)
        //canvas.drawRect(rect,paint)

       // canvas.translate(-100f,-100f)
       //val rect2=Rect(100,100,300,200)
        //canvas.drawRect(rect2,paint)

        //根据原点旋转45度
        //canvas.rotate(45f)
        //canvas.drawRect(rect2,paint)
        //scale 缩放坐标系密度
        val paint2=Paint()
        paint2.color=Color.parseColor("#fc4c4f")
        paint2.isAntiAlias=true
        paint2.strokeWidth=5f
        paint2.style=Paint.Style.STROKE
        //val rect1 = Rect(10, 10, 200, 100)
       // canvas.drawRect(rect1, paint)

       // canvas.scale(0.5f, 1f)
       // canvas.drawRect(rect1, paint2)
        //skew 扭曲

        val rect1 = Rect(10, 10, 200, 100)
        canvas.drawRect(rect1,paint)

        canvas.skew(Math.tan(45.0).toFloat(),0f)
        canvas.drawRect(rect1,paint2)


    }
}